from datetime import datetime

from django.core.signals import request_started
from django.http import HttpResponse
from django.shortcuts import render
from django.template.context_processors import request

from book.models import BookInfo


# Create your views here.
def create_book(request):

    book = BookInfo.objects.create(
        name='abc',
        pub_date='2025-6-13',
        readcount=10,
    )
    return HttpResponse("create")

def shop(request,city_id,shop_id):
    import re
    # print(city_id,shop_id)
    # return HttpResponse("一个简单的shop")
    # query_parms=request.GET #获取查询字符串
    # print(query_parms)
    # order = (query_parms.get('order'))
    # print(order)


def register(request):
    data = request.POST
    print(data)
    return HttpResponse("ok")

def json(request):
    body=request.body
    #print(body)
    body_str=body.decode('utf-8')
    #JSON形式的字符串可以转换为python的字典
    import json
    body_dict=json.loads(body_str)
    print(body_dict) #{'name': 'itcast', 'age': 10}
    #print(request.META)
    return HttpResponse("json")
########################
"""
查询字符串
htto://ip:port/path/path/?key=value&key1=value
? 为分隔，前边为请求路径，后边为查询字符串
查询字符串类似与字典
"""